import axios from 'axios';
import React from 'react'
import { useLocation } from 'react-router-dom'
import { Button } from 'react-vant';

const Order: React.FC = () => {
  const location = useLocation();
  const { totalPrice } = location.state;
  const title = '这是一件商品'
  const id = new Date().getTime();

  const handlePay = async () => {
    const data = {
      title, id, totalPrice
    }
    const resp = await axios.post('/api/pay', data);
    window.location.href = resp.data.data
  }

  return (
    <div>
      <div>
        <h2>订单号：{ id }</h2>
        <h2>标题：{ title }</h2>
        <h2>总价钱：{ totalPrice }</h2>
      </div>
      <Button type="primary" block onClick={() => handlePay() }>立即支付</Button>
    </div>
  )
}


export default Order